From fcb05d24873db89c94304f10d8e75ee49ac797bd Mon Sep 17 00:00:00 2001 From: tsteven4 Date: Sat, 16 Mar 2013 14:38:06 +0000 Subject: [PATCH] gpx writer, garminextensions option: fix bug with magic values causing extension data to be lost. --- gpsbabel/gpx.cc | 22 ++-- gpsbabel/reference/extensiondata.unicsv | 6 + gpsbabel/reference/extensiondata~unicsv.gpx | 128 ++++++++++++++++++++ gpsbabel/testo.d/gpx.test | 3 + 4 files changed, 148 insertions(+), 11 deletions(-) create mode 100644 gpsbabel/reference/extensiondata.unicsv create mode 100644 gpsbabel/reference/extensiondata~unicsv.gpx diff --git a/gpsbabel/gpx.cc b/gpsbabel/gpx.cc index 1c11c8259..5d27c0eca 100644 --- a/gpsbabel/gpx.cc +++ b/gpsbabel/gpx.cc @@ -1657,16 +1657,16 @@ static void gpx_write_common_extensions(const waypoint* waypointp, const gpx_point_type point_type) { // gpx version we are writing is >= 1.1. - if ((opt_humminbirdext && (waypointp->depth != 0 || waypointp->temperature != 0)) || - (opt_garminext && gpxpt_waypoint==point_type && (waypointp->temperature != 0 || waypointp->depth != 0)) || - (opt_garminext && gpxpt_track==point_type && (waypointp->temperature != 0 || waypointp->depth != 0 || waypointp->heartrate != 0 || waypointp->cadence != 0))) { + if ((opt_humminbirdext && (WAYPT_HAS(waypointp, depth) || WAYPT_HAS(waypointp, temperature))) || + (opt_garminext && gpxpt_waypoint==point_type && (WAYPT_HAS(waypointp, temperature) || WAYPT_HAS(waypointp, depth))) || + (opt_garminext && gpxpt_track==point_type && (WAYPT_HAS(waypointp, temperature) || WAYPT_HAS(waypointp, depth) || waypointp->heartrate != 0 || waypointp->cadence != 0))) { writer.writeStartElement("extensions"); if (opt_humminbirdext) { - if (waypointp->depth != 0) { + if (WAYPT_HAS(waypointp, depth)) { writer.writeTextElement("h:depth", toString(waypointp->depth * 100.0)); } - if (waypointp->temperature != 0) { + if (WAYPT_HAS(waypointp, temperature)) { writer.writeTextElement("h:temperature", toString(waypointp->temperature)); } } @@ -1678,12 +1678,12 @@ gpx_write_common_extensions(const waypoint* waypointp, const gpx_point_type poin // Although not required by the schema we assume that gpxtpx:TrackPointExtension must be a child of gpx:trkpt. switch (point_type) { case gpxpt_waypoint: - if (waypointp->temperature != 0 || waypointp->depth != 0) { + if (WAYPT_HAS(waypointp, temperature) || WAYPT_HAS(waypointp, depth)) { writer.writeStartElement("gpxx:WaypointExtension"); - if (waypointp->temperature != 0) { + if (WAYPT_HAS(waypointp, temperature)) { writer.writeTextElement("gpxx:Temperature", toString(waypointp->temperature)); } - if (waypointp->depth != 0) { + if (WAYPT_HAS(waypointp, depth)) { writer.writeTextElement("gpxx:Depth", toString(waypointp->depth)); } writer.writeEndElement(); // "gpxx:WaypointExtension" @@ -1693,13 +1693,13 @@ gpx_write_common_extensions(const waypoint* waypointp, const gpx_point_type poin /* we don't have any appropriate data for the children of gpxx:RoutePointExtension */ break; case gpxpt_track: - if (waypointp->temperature != 0 || waypointp->depth != 0 || waypointp->heartrate != 0 || waypointp->cadence != 0) { + if (WAYPT_HAS(waypointp, temperature) || WAYPT_HAS(waypointp, depth) || waypointp->heartrate != 0 || waypointp->cadence != 0) { // gpxtpx:TrackPointExtension is a replacement for gpxx:TrackPointExtension. writer.writeStartElement("gpxtpx:TrackPointExtension"); - if (waypointp->temperature != 0) { + if (WAYPT_HAS(waypointp, temperature)) { writer.writeTextElement("gpxtpx:atemp", toString(waypointp->temperature)); } - if (waypointp->depth != 0) { + if (WAYPT_HAS(waypointp, depth)) { writer.writeTextElement("gpxtpx:depth", toString(waypointp->depth)); } if (waypointp->heartrate != 0) { diff --git a/gpsbabel/reference/extensiondata.unicsv b/gpsbabel/reference/extensiondata.unicsv new file mode 100644 index 000000000..aa2241ee1 --- /dev/null +++ b/gpsbabel/reference/extensiondata.unicsv @@ -0,0 +1,6 @@ +name, lat, lon, ele,depth,temp,heart,caden +Lickskillet, 40.075297, -105.414373, 2294, , 20, 60, 85 +Gold Hill, 40.063311, -105.409614, 2514, , 18, 160, 45 +Barker Reservoir Dam, 39.966120, -105.482821, 2499, 37, , 50, +Barker Reservoir Shore, 39.962905, -105.502236, 2499, 0, , 40, +James Peak, 39.852048, -105.690364, 4063, , 0, 70, diff --git a/gpsbabel/reference/extensiondata~unicsv.gpx b/gpsbabel/reference/extensiondata~unicsv.gpx new file mode 100644 index 000000000..806b170b9 --- /dev/null +++ b/gpsbabel/reference/extensiondata~unicsv.gpx @@ -0,0 +1,128 @@ + + + + + + + + 2294.000000 + Lickskillet + Lickskillet + Lickskillet + + + 20.000000 + + + + + 2514.000000 + Gold Hill + Gold Hill + Gold Hill + + + 18.000000 + + + + + 2499.000000 + Barker Reservoir Dam + Barker Reservoir Dam + Barker Reservoir Dam + + + 37.000000000 + + + + + 2499.000000 + Barker Reservoir Shore + Barker Reservoir Shore + Barker Reservoir Shore + + + 0.000000000 + + + + + 4063.000000 + James Peak + James Peak + James Peak + + + 0.000000 + + + + + + + 2294.000000 + Lickskillet + Lickskillet + Lickskillet + + + 20.000000 + 60 + 85 + + + + + 2514.000000 + Gold Hill + Gold Hill + Gold Hill + + + 18.000000 + 160 + 45 + + + + + 2499.000000 + Barker Reservoir Dam + Barker Reservoir Dam + Barker Reservoir Dam + + + 37.000000000 + 50 + + + + + 2499.000000 + Barker Reservoir Shore + Barker Reservoir Shore + Barker Reservoir Shore + + + 0.000000000 + 40 + + + + + 4063.000000 + James Peak + James Peak + James Peak + + + 0.000000 + 70 + + + + + + diff --git a/gpsbabel/testo.d/gpx.test b/gpsbabel/testo.d/gpx.test index 60b35c7ab..6f2271685 100644 --- a/gpsbabel/testo.d/gpx.test +++ b/gpsbabel/testo.d/gpx.test @@ -17,3 +17,6 @@ rm -f ${TMPDIR}/basecampe~gpx.gpx gpsbabel -i gpx -f ${REFERENCE}/basecamp.gpx -o gpx -F ${TMPDIR}/basecamp~gpx.gpx compare ${REFERENCE}/basecamp~gpx.gpx ${TMPDIR}/basecamp~gpx.gpx +rm -f ${TMPDIR}/extensiondata.gpx +gpsbabel -i unicsv -f ${REFERENCE}/extensiondata.unicsv -x transform,trk=wpt -o gpx,garminextensions -F ${TMPDIR}/extensiondata.gpx +compare ${REFERENCE}/extensiondata~unicsv.gpx ${TMPDIR}/extensiondata.gpx -- 2.30.2